#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<vector>
using namespace std;

char to(char ch)
{
	if (ch == '9')
		return '6';
	else if (ch == '6')
		return '9';
	else
		return ch;
}
string Reverse(const string str)
{
	string nexstr;
	for (int i = 3; i >= 0; i--)
	{
		nexstr.push_back(to(str[i]));
	}
	return nexstr;
}
struct price
{
	int a, b, c;
};
vector<price> v1;
vector<price> v2;

int main()
{
	/*string str1("1958");
	cout << Reverse(str1) << endl;*/
	for (int i = 1000; i <= 9999; i++)
	{
		string str1 = to_string(i);
		if (str1.find('3') != -1 || str1.find('4') != -1 || str1.find('7') != -1|| str1.rfind('0') == str1.size()-1)
		{
			continue;
		}
		string r = Reverse(str1);
		int rint = stoi(r);
		if (rint - i > -300 && rint - i < -200)
		{
			price p = { rint, i, rint - i };
			v1.push_back(p);
		}
		else if (rint - i > 800 && rint - i < 900)
		{
			price p = { rint, i, rint - i };
			v2.push_back(p);
		}

		for (int j = 0; j < v1.size(); j++)
		{
			for (int k = 0; k < v2.size(); k++)
			{
				if (v1[j].c + v2[k].c == 558)
				{
					printf("%d %d %d %d\n", v1[j].a, v1[j].b, v1[k].a, v1[k].b);
				}
			}
		}

	}
	return 0;
}